#include <iostream>
#include <fstream>
#include "contacts.pb.h"

int main()
{
    contacts::Contacts cons;
    std::ifstream in("contacts.bin", std::ios::in | std::ios::binary);
    if (!in.is_open())
    {
        std::cout << "open contacts.bin error!" << std::endl;
        return -1;
    }
    else if (!cons.ParsePartialFromIstream(&in))
    {
        std::cout << "反序列化失败!" << std::endl;
        return -1;
    }
    
    for(int i = 0;i<cons.contacts_size();i++)
    {
        std::cout<<"-------------------------------"<<std::endl;
         std::cout<<"------------联系人-------------"<<std::endl;
        auto people = cons.contacts(i);
        std::cout<<"姓名: ";
        std::cout<<people.name()<<std::endl;
        std::cout<<"年龄: "<<people.age()<<std::endl;
        std::cout<<"-----------联系电话-------------"<<std::endl;
        for(int i = 0;i<people.phones_size();i++)
        {
            std::cout<<(people.phones(i)).phone()<<std::endl;
        }
        std::cout<<"----------- 联系人-------------"<<std::endl;
         std::cout<<"-----------------------------"<<std::endl;
    }
    in.close();
    return 0;
}